<?php

    require_once '../../model/global.inc.php'; 
  //check to see that the form has been submitted
    $str = $_POST['selectedname'];
    $str=substr(trim($str), 0, -1);
    $arr = split(',',$str);
    //$arr = split(",",$_POST['selectedname']);
    print_r($arr);
    
    //retrieve the $_POST variables  
    $pro_name = $_POST['pro_name'];  
    $pro_desc = $_POST['pro_desc'];  
    $price = $_POST['pro_prince'];
    $pro_prince = (double)$price;  
    $categories = $_POST['pro_cate'];                    
    
    $success=true;
    $result = mysql_query("SELECT categories_id FROM tblcategories where categories_name = '$categories'");

    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
    { 
            $categories_id = $row["categories_id"];

    }

    if($success)  
    {  
        //prep the data for saving in a new user object  
        $data['pro_name'] = $pro_name;  
        $data['pro_desc'] = $pro_desc; //encrypt the password for storage  
        $data['pro_prince'] = $pro_prince;                       
        $data['categories_id'] = $categories_id;
        for($i=0;$i<=sizeof($arr);$i++)
        {
             echo $data['pro_image'.$i] = $arr[$i];
        }

        //create the new user object  
        $pro = new Pro($data);  
        print_r($pro);
        //save the new user to the database  
        $pro->insertPro();     
        echo "<script>alert('Insert success');</script>";

    }  
?>
